//
//  UIButton+Extension.swift
//  sina----
//
//  Created by mac on 16/5/8.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

extension UIButton {


    convenience init(
        title: String?,
        color: UIColor = UIColor.darkGrayColor(),
        font: CGFloat = 17,
        imageName: String? = nil,
        backgroundImageName: String? = nil) {
        
            self.init()

            self.setTitle(title, forState: .Normal)
            self.setTitleColor(color, forState: .Normal)
            self.titleLabel?.font = UIFont.systemFontOfSize(font)
            
            
            if let imageName = imageName {
                setImage(UIImage(named: imageName), forState: .Normal)
                setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
            }
            if let backgroundImageName = backgroundImageName {
                setBackgroundImage(UIImage(named: backgroundImageName), forState: .Normal)
                setBackgroundImage(UIImage(named: backgroundImageName + "_highlighted"), forState: .Highlighted)
            }
            sizeToFit()
    }
}
